﻿package test {
	import extremefx.data.DataSource;
	import extremefx.events.EventArgs;
	import extremefx.geom.Size;
	import extremefx.storage.LoadQeue;
	import extremefx.tools.Profiler;
	import extremefx.ui.Button;
	import extremefx.ui.Checkbox;
	import extremefx.ui.Container;
	import extremefx.ui.DropDown;
	import extremefx.ui.HScrollBar;
	import extremefx.ui.Input;
	import extremefx.ui.ItemList;
	import extremefx.ui.RadioGroup;
	import extremefx.ui.ScrollPane;
	import extremefx.ui.StyleManager;
	import extremefx.ui.UIStage;
	import extremefx.ui.VScrollBar;
	import extremefx.ui.layout.HVLayout;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	/*FDT_IGNORE*/
	import gpi.skin.arrowDown;
	/*FDT_IGNORE*/
	
	/**
	 * @author Marcelo Volmaro
	 */
	 
	[Frame(factoryClass="extremefx.Preloader")];
	public class ComponentTest extends Sprite {
		
		private var _cont:Container;
		private var _loader:LoadQeue;

		public function main():void {
			Profiler.init(this.stage, this);
			UIStage.init(this.stage);
			
			_loader = new LoadQeue();

			
			StyleManager.init(_loader);
			
			_loader.onQeueComplete.add(doWork);
			
			/**
			 * Progress bar % formula:
			 * f(x) = (x+(1-x)/2)^8
			 */
			 
//			for (var i:uint = 0; i<=100; i++){
//				var p:Number = i / 100;
//				trace(Math.pow((p + (1 - p) / 2), 8));
//			}

/*FDT_IGNORE*/
//includes the skin assets...
			var a:gpi.skin.arrowDown;
			var b:gpi.skin.arrowLeft;
			var c:gpi.skin.arrowRight;
			var d:gpi.skin.arrowUp;
			var e:gpi.skin.buttons;
			var f:gpi.skin.buttonTabFocus;
			var g:gpi.skin.checkbox;
			var h:gpi.skin.dropDown;
			var i:gpi.skin.genericTabFocus;
			var j:gpi.skin.hScrollBar;
			var k:gpi.skin.hThumb;
			var l:gpi.skin.input;
			var m:gpi.skin.inputBackground;
			var n:gpi.skin.itemList;
			var o:gpi.skin.itemListBack;
			var p:gpi.skin.listItem;
			var q:gpi.skin.radio;
			var r:gpi.skin.vScrollBar;
			var s:gpi.skin.vThumb;
/*FDT_IGNORE*/			
		}
		
		private function doWork(pSender:LoadQeue, pArgs:EventArgs):void {
			var stage:Stage = UIStage.STAGE;
			stage.addEventListener(Event.RESIZE, resizeStage);
			
			var c:Container = _cont = new Container();
			var hl:HVLayout = new HVLayout();
//			hl.alignment = UIAlign.RIGHT | UIAlign.BOTTOM;
			hl.isVertical = true;
			hl.hMargin = hl.vMargin = 16;
			
			c.layoutManager = hl;
			
			var b:Button = new Button("@test2");
			c.add(b);
//			b.assignKey(Keyboard.ENTER);
			
			var b1:Button = new Button("Button 2");
			c.add(b1);
			
			b = new Button("Button 3");
			c.add(b);
			
			var r:RadioGroup = new RadioGroup();
			r.setDataSource(new DataSource(["Radio 1", "Radio 2", "Radio 3"]));
			c.add(r);
			
			b = new Button("Enable/Disable Checkbox");
			c.add(b);
			b.onClick.add(function(pSender:Button, pArgs:EventArgs):void{
				cb.enabled = !cb.enabled;
			});
			
			var cb:Checkbox = new Checkbox("A nice checkbox");
			c.add(cb);
			
			var i:Input = new Input(null, true);
			i.size = new Size(200,100);
			c.add(i);
			
			var vs:VScrollBar = new VScrollBar();
			vs.size = new Size(200,200);
			vs.setScrollProperties(500, 0, 500);
			c.add(vs);
			
			var hs:HScrollBar = new HScrollBar();
			hs.size = new Size(200, 200);
			hs.setScrollProperties(500, 0, 500);
			c.add(hs);
			
			var sp:ScrollPane = new ScrollPane();
			sp.size = new Size(200, 200);
			c.add(sp);
			sp.content = new RectangleClass() as Sprite;
			
			var li:ItemList = new ItemList();
			li.size = new Size(200, 200);
			c.add(li);
			
			var a:Array = [];
			for (var n:uint = 0; n<100; n++){
				a.push("Item "+n);
			}
			
			li.setDataSource(new DataSource(a));
			li.selectedIndex = 90;
			
			var dd:DropDown = new DropDown();
			dd.size = new Size(200, 200);
			c.add(dd);
			
			dd.setDataSource(new DataSource(a));
			dd.selectedIndex = 92;
			
			c.attachToDisplay(UIStage.ROOT);
			c.size = new Size(stage.stageWidth - 1, stage.stageHeight - 1);
		}
		
		private function resizeStage(event:Event = null):void {
			_cont.size = new Size(stage.stageWidth - 1, stage.stageHeight - 1);
		}
	}
}
